package com.hliushi.util;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * @author llhuang10
 * @date 2021/8/19 14:34
 */
@Slf4j
public class PropertiesUtil {

    public static String getProp(String propName, String path) {
        String value = "";
        Properties prop = new Properties();
        InputStream is = null;
        try {
            is = PropertiesUtil.class.getClassLoader().getResourceAsStream(path);
            // 加载属性列表
            prop.load(is);
            for (String s : prop.stringPropertyNames()) {
                if (s.equals(propName)) {
                    value = prop.getProperty(propName);
                }
            }
            return value.trim();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static Map<String, String> getProp(List<String> propList, String path) {
        List<String> list = new ArrayList<>();
        propList.forEach(item -> list.add(getProp(item, path)));

        return null;
    }

    public static void main(String[] args) {
        String className = PropertiesUtil.getProp("className", "temp/_01Factory.properties");
        System.out.println("className = " + className);
    }
}
